/////////////////////////////////////////////////////////////////////////////
// Name:        dgt_FileDialog.cpp
// Purpose:     
// Author:      Aleksey Plotnikov & Alla Nabatova
// Modified by: 
// Created:     16/05/2008 13:23:01
// RCS-ID:      
// Copyright:   Diamant Software
// Licence:     
/////////////////////////////////////////////////////////////////////////////

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dgt_FileDialog.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "dgt_FileDialog.h"
#include "dgt_PluginManager.h"
#include "dgt_StudioApp.h"
#include "dgt_StorePlugin.h"

////@begin XPM images
////@end XPM images


/*!
 * dgt_FileDialog type definition
 */

IMPLEMENT_DYNAMIC_CLASS( dgt_FileDialog, wxDialog )


/*!
 * dgt_FileDialog event table definition
 */

BEGIN_EVENT_TABLE( dgt_FileDialog, wxDialog )

////@begin dgt_FileDialog event table entries
////@end dgt_FileDialog event table entries

END_EVENT_TABLE()


/*!
 * dgt_FileDialog constructors
 */

dgt_FileDialog::dgt_FileDialog()
{
    Init();
}

dgt_FileDialog::dgt_FileDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create(parent, id, caption, pos, size, style);
}

dgt_FileDialog::dgt_FileDialog(wxWindow *parent, bool isOpen, wxWindowID id, const wxString &caption, const wxPoint &pos, const wxSize &size, long style)
{
	m_Open = isOpen;
	Init();
	Create( parent, id, caption, pos, size, style );
}


/*!
 * dgt_FileDialog creator
 */

bool dgt_FileDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin dgt_FileDialog creation
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end dgt_FileDialog creation
    return true;
}


/*!
 * dgt_FileDialog destructor
 */

dgt_FileDialog::~dgt_FileDialog()
{
////@begin dgt_FileDialog destruction
////@end dgt_FileDialog destruction
}


/*!
 * Member initialisation
 */

void dgt_FileDialog::Init()
{
////@begin dgt_FileDialog member initialisation
    m_Dir = NULL;
    m_Label = NULL;
    m_Choice = NULL;
    m_ActionButton = NULL;
////@end dgt_FileDialog member initialisation
}


/*!
 * Control creation for dgt_FileDialog
 */

void dgt_FileDialog::CreateControls()
{    
////@begin dgt_FileDialog content construction
    dgt_FileDialog* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    m_Dir = new wxGenericDirCtrl( itemDialog1, ID_GENERICDIRCTRL, _T(""), wxDefaultPosition, wxSize(400, 300), wxSIMPLE_BORDER, _T("All files (*.*)|*.*"), 0 );
    itemBoxSizer3->Add(m_Dir, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticLine* itemStaticLine5 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
    itemBoxSizer2->Add(itemStaticLine5, 0, wxGROW|wxALL, 5);

    wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer6, 1, wxGROW|wxALL, 5);

    m_Label = new wxStaticText( itemDialog1, wxID_STATIC, _("Plugin for open:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer6->Add(m_Label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString m_ChoiceStrings;
    m_Choice = new wxChoice( itemDialog1, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, m_ChoiceStrings, 0 );
    itemBoxSizer6->Add(m_Choice, 1, wxGROW|wxALL, 5);

    m_ActionButton = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer6->Add(m_ActionButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

////@end dgt_FileDialog content construction

	if( m_Open )
	{
		this->SetTitle( _("Opening schema") );
		m_Label->SetLabel( _("Plugin for open") );
		m_ActionButton->SetLabel( _("Open") );
	}
	else
	{
		this->SetTitle( _("Saving schema") );
		m_Label->SetLabel( _("Plugin for save") );
		m_ActionButton->SetLabel( _("Save") );
	}

	dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
	dgt_PluginManager *pManager = tApp->get_Manager();

	int pCount = pManager->get_PluginCount( PLUGIN_STORE );

	for( unsigned i = 0; i < pCount; i++ )
	{
		dgt_Plugin_Ptr pPlugin = pManager->get_Plugin( PLUGIN_STORE, i );

		if( pPlugin.get() )
		{
			dgt_PluginInfo tInfo;

			pPlugin->GetPluginInfo( tInfo );
			m_Choice->AppendString( tInfo.m_PluginName );
		}
	}
}


/*!
 * Should we show tooltips?
 */

bool dgt_FileDialog::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap dgt_FileDialog::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin dgt_FileDialog bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end dgt_FileDialog bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon dgt_FileDialog::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin dgt_FileDialog icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end dgt_FileDialog icon retrieval
}

wxString dgt_FileDialog::get_DBName()
{
	return m_Dir->GetPath();
}
